#include <vector>
#include <string>

/*
构建者模式: 由产品类，构建类，产品经理类构成
*/

class Computer{
private:
    std::vector<std::string> componetList;

public:
    void addComponetList(std::string name)
    {
        componetList.push_back(name);
    }

    void showComponets()
    {
        printf("Computer: ");
        for(int i = 0; i <componetList.size(); i++)
        {
            printf("%s ", componetList[i].c_str());
        }
        printf("\n");
    }
};


class BuilderBase{
public:
    virtual void addLogo() = 0;
    virtual void addMCU() = 0;
    virtual void addDisk() = 0;
    virtual void addScreen() = 0;
    virtual void addSystem() = 0;
    virtual Computer* getComputer() = 0;
    virtual ~BuilderBase() {}
};


//这个类只组装华为的电脑，还可以创建其他类组装其他品牌电脑
class HuaweiComputerBuilder : public BuilderBase{
public:
    Computer* computer = nullptr;

public:
    HuaweiComputerBuilder(){
        computer = new Computer();
    }

    ~HuaweiComputerBuilder(){
        if(computer){
            delete computer;
        }
    }

    Computer* getComputer(){
        return computer;
    }

    void addLogo(){
        computer->addComponetList("HUAWEI");
    }
    void addMCU(){
        computer->addComponetList("MCU");
    }

    void addDisk(){
        computer->addComponetList("Disk");
    }

    void addScreen(){
        computer->addComponetList("Screen");
    }
    void addSystem(){
        computer->addComponetList("System");
    }
};


//产品经理类，可以控制产线组装哪些部件。
class Director{
public:
    static Computer* produceComputer(BuilderBase* builder){
        builder->addLogo();
        builder->addDisk();
        builder->addSystem();
    }
};